<!DOCTYPE html>
<html lang="zh-CN">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Vue入门指南——事件处理</title>
    <link rel="stylesheet" href="common.css" />
    <script type="importmap">
      {
        "imports": {
          "vue": "https://lib.baomitu.com/vue/latest/vue.esm-browser.js"
        }
      }
    </script>
  </head>
  <body>
    <div id="app">
      <p>
        <button @click="count++">内联事件处理器</button>
        计数:{{count}}
      </p>
      <p>
        <button @click="greet">方法事件处理器</button>
      </p>
      <p>
        <button @click="say('内联处理器调用方法', $event)">
          内联处理器调用方法
        </button>
      </p>
      <p>
        <input type="text" @keyup.ctrl.enter="doSomething" />
        <label>Ctrl+Enter执行</label>
      </p>
    </div>
    <script type="module">
      import { createApp } from "vue";

      createApp({
        data() {
          return {
            count: 0,
            name: "方法事件处理器",
          };
        },
        methods: {
          greet(event) {
            alert(this.name);
            if (event) {
              alert(event.target.tagName);
            }
          },
          say(msg, event) {
            alert(msg);
            if (event) {
              alert(event.target.tagName);
            }
          },
          doSomething(event) {
            alert("Ctrl+Enter");
            if (event) {
              alert(event.target.value);
            }
          },
        },
      }).mount("#app");
    </script>
  </body>
</html>
